{% extends "double.html" %}

{% block title %}{{ page_title }}{% endblock %}
{% block styles %}
    <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}styles/home.css">
{% endblock %}
{% block scripts %}
    <script type="text/javascript" src="{{ STATIC_URL }}scripts/jquery.blockUI.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var sectionheight = $('section').height();
            $('aside').height(sectionheight);

            var formleft = document.width / 2 - $('.rtweetform').width() / 2;

            $('.rtweet').click(function(){
                $.blockUI({ 
                    message: $('.rtweetform'),
                    css: {
                        width: '700',
                        height:'140',
                        left: formleft,
                    }
                });  
                $('#id_rtmessage').css({
                    'width': '600px',
                    'height': '70px',
                    'border': '1px solid rgb(125, 198, 221)'})
                $('.rtsubmit').css({
                    'width': '60px', 
                    'height': '25px', 
                    'border': 'none',
                    'cursor': 'pointer',
                    'background': '#fcebbd',
                    'color': '#af9540',
                    'border-radius': '3px',
                    'float': 'right',
                    'display': 'inline-block',
                    'margin': '0 45px 0 0',
                })

                var posturlid = $(this).attr('data-tweet');
                var aciton = '/{{ user.username }}/rtweet/'+ posturlid + '/'
                var formaction = $('.rtweetform form').attr('action', aciton)
                console.log(aciton)

                var tweetgroup = $(this).parent('.operating').siblings('.tweetgroup')
                var reuser = tweetgroup.find('.tweetuser').text()

                if (tweetgroup.find('.origntweet').length > 0){
                    var retweet = tweetgroup.find('.tweetcontent').text()
                    var recontent = '// RT' + reuser + ' ' + retweet; 
                }else{
                    var recontent = 'RT'
                    
                }
                $('#id_rtmessage').text(recontent)
            })
            $('.blockOverlay').live('click',function(){
                $.unblockUI();
            })
        })
    </script>
{% endblock %}

{% block main %}    
    {% include 'include/postform.html' %}
<div class="bloglist">
    <ul>
        {% if tweets %}
            {% for tweet in tweets %}
                <li>
                    <div class="avatar50">
                        <img src="{{ MEDIA_URL }}avatar/50/{{ tweet.user.profile.avatar }}">
                    </div>

                    <div class="tweetgroup">
                        <div class="currenttweet">
                            <div class="tweetwarp">
                                <a class="tweetuser" href="{{ tweet.user.profile.get_user_index_url }}">@{{ tweet.user.username }}: </a>
                                <div class="tweetcontent">{{ tweet.message|urlize }}</div>
                            </div>
                        </div>
                        {% if tweet.orginmessage %}
                            <div class="origntweet">
                                <a class="tweetuser" href="{{ tweet.orginmessage.user.get_user_index_url }}">@{{ tweet.orginmessage.user.username }}: </a>
                                <div class="retweetcontent">{{ tweet.orginmessage|urlize }}</div>
                                <em class="readdtime">{{ tweet.orginmessage.addtime_format_admin }}</em>
                            </div>
                        {% endif %}
                        <div class="clear"></div>
                    </div>

                    <div class="addtime">
                        <em>{{ tweet.addtime|timesince}}</em>
                    </div>
                    <div class="operating">
                        <a href="{% url mblog_tweetdetail user.username tweet.id %}">评论({{ tweet.replyer_set.count|default:'0' }})</a>
                        {% if user in tweet.favorite.favuser.all  %}
                            <a href="{% url mblog_favorite_del user.username  tweet.favorite.id %}">取消收藏({{ tweet.favorite.favuser.count }})</a>
                        {% else %}
                            <a href="{% url mblog_favorite_add user.username  tweet.id %}">收藏({{ tweet.favorite.favuser.count|default:'0' }})</a>
                        {% endif %}
                        {% if tweet.orginmessage %}
                            <a class="rtweet" href="javascript:;" data-tweet="{{ tweet.orginmessage.id }}">转发</a>
                        {% else %}
                            <a class="rtweet" href="javascript:;" data-tweet="{{ tweet.id }}">转发</a>
                        {% endif %}
                    </div> 
                    <div class="clear"></div>
                </li>
            {% endfor %}
        {% endif %}
    </ul>
</div>
{% include 'include/paginator.html' %}

<div class="rtweetform" style="display:none">
    <h5>转发</h5>
    <form method="post" action="">
        {% csrf_token %}
        <p><input type="hidden" name="next" value="/" /></p>  
        <p>
            {{ rtform.rtmessage }}
            {% if rtform.rtmessage.errors %}
                <strong>
                {% for error in rtform.rtmessage.errors %}
                    {{ error|escape }}
                {% endfor %}
                </strong>
            {% endif %}
        </p>
        <input type="submit" class="rtsubmit" value="转发">
    </form>
</div>

{% endblock %}
{% block aside %}
    <div class="userinfo">
        <div class="asideavatar50">
            <img src="{{ MEDIA_URL }}avatar/50/{{ taruser.profile.avatar }}" class="img_avatar" alt="我的头像" />
        </div>
        <a href="{{ taruser.profile.get_user_index_url }}">{{ taruser.username }}</a>
        <div class="clear"></div>
    </div>

    <ul id="user_stats">
        <li><a href="{% url mblog_followers taruser.username %}"><span class="count">{{ taruser.follower_set.count }}</span><span class="label">关注者</span></a></li>
        <li><a href="{% url mblog_fans taruser.username %}"><span class="count">{{ taruser.fan_set.count }}</span><span class="label">粉丝</span></a></li>
        <li><a href=""><span class="count">{{ taruser.tweet_set.count }}</span><span class="label">消息</span></a></li>
        <li><a href="{% url mblog_favoritelist taruser.username %}"><span class="count">{{ taruser.favorite_set.count }}</span><span class="label">收藏</span></a></li>
    </ul>
{% endblock %}
